import java.sql.*;

public class Main {

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        /*Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection connect = DriverManager.getConnection("jdbc:oracle:thin:@//192.168.0.50:1521/ecology", "ecology", "OracleWEAVER#50");
        Statement statement = connect.createStatement();
        statement.execute("create table t_test0605 (a varchar(100))");
        System.out.println("create table t_test0605");
        statement.execute("insert into t_test0605 values('111111')");
        statement.execute("insert into t_test0605 values('333333')");
        ResultSet resultSet = statement.executeQuery("select * from t_test0605");
        while (resultSet.next()) {
            String string = resultSet.getString(1);
            System.out.println("查询结果：" + string);
        }
        statement.execute("update t_test0605 set a='222' where a='111111'");
        System.out.println("update");
        statement.execute("delete from t_test0605 where a='222'");
        System.out.println("delete");
        statement.execute("drop table t_test0605 ");
        System.out.println("删表");
        resultSet.close();
        connect.close();*/

//        test2();

        test1();
    }


    public static void test1() throws SQLException {

        Connection connect = DriverManager.getConnection("jdbc:postgresql://172.16.55.173:2215/vastbase", "zxs", "Vastdata#0730");
        String sql = "select *  from public.test_data_type";
        Statement statement = connect.createStatement();
        String schema = connect.getSchema();
        System.out.println("schema:" + schema);
        String catalog = connect.getCatalog();
        System.out.println("catalog:" + catalog);


        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()) {
            System.out.println("111" + resultSet.getObject(1).getClass().getName());
        }
        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();

        int columnCount = resultSetMetaData.getColumnCount();
        for (int i = 1; i <= columnCount; i++) {
            String columnName = resultSetMetaData.getColumnName(i);
            System.out.println("columnName:" + columnName);
            String catalogName = resultSetMetaData.getCatalogName(i);
            System.out.println("catalogName:" + catalogName);
            int columnType = resultSetMetaData.getColumnType(i);
            String columnTypeName = resultSetMetaData.getColumnTypeName(i);
            System.out.println(columnTypeName);

        }
    }


    public static void test2() throws SQLException {
        // ?db_compatibility=oracle&resultCaseMode=upper
        Connection connect = DriverManager.getConnection("jdbc:postgresql://172.16.55.185:5001/vastbase", "zxs", "Vastdata#0730");
        String sql = "select *  from t_user";
        Statement statement = connect.createStatement();
        String schema = connect.getSchema();
        System.out.println("schema:" + schema);
        String catalog = connect.getCatalog();
        System.out.println("catalog:" + catalog);


        ResultSet resultSet = statement.executeQuery(sql);
        ResultSetMetaData resultSetMetaData = resultSet.getMetaData();

        int columnCount = resultSetMetaData.getColumnCount();
        for (int i = 1; i <= columnCount; i++) {
            String columnName = resultSetMetaData.getColumnName(i);
            System.out.println("columnName:" + columnName);
            String catalogName = resultSetMetaData.getCatalogName(i);
            System.out.println("catalogName:" + catalogName);

        }
    }



}



